package cn.itcast.star.graph.core.service.impl;

import cn.itcast.star.graph.comfyui.client.pojo.ComfyuiModel;
import cn.itcast.star.graph.core.service.FreemarkerService;
import freemarker.template.Configuration;
import freemarker.template.Template;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;

@Service
public class FreemarkerServiceImpl implements FreemarkerService {

    @Autowired
    Configuration configuration;

    @Override
    public String rederText2Image(ComfyuiModel comfyuiModel) throws Exception {
        Template template = configuration.getTemplate("t2i.ftlh");
        Map<String, ComfyuiModel> data = new HashMap<>();
        data.put("config", comfyuiModel);
        StringWriter out = new StringWriter();
//        FileWriter out = new FileWriter("D:prompt.txt");  //文件输出流
        template.process(data, out);    //使用数据替换模板
        return out.toString();
    }
}
